package springboot.bigdata.demo.dao.impl;

import cn.hutool.core.collection.CollUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import springboot.bigdata.demo.dao.UserServiceItemDao;
import springboot.bigdata.demo.mappers.db0.DB0UserServiceItemMapper;
import springboot.bigdata.demo.mappers.db1.DB1UserServiceItemMapper;
import springboot.bigdata.demo.model.UserServiceItem;

import java.util.List;

@Component
public class UserServiceItemDaoImpl implements UserServiceItemDao {

    @Autowired
    private DB0UserServiceItemMapper db0UserServiceItemMapper;
    @Autowired
    private DB1UserServiceItemMapper db1UserServiceItemMapper;

    @Override
    public UserServiceItem add(UserServiceItem userServiceItem) {

        if (userServiceItem.getServiceItemId() %2 == 0){
            db0UserServiceItemMapper.insertSelective(userServiceItem);
        }else {
            db1UserServiceItemMapper.insertSelective(userServiceItem);
        }

        return userServiceItem;

    }

    @Override
    public int addList(List<UserServiceItem> userServiceItemList, int dbType) {

        if (CollUtil.isEmpty(userServiceItemList)){
            return 0;
        }

        if (dbType == 0){
            db0UserServiceItemMapper.insertSelectiveList(userServiceItemList);
        }else if (dbType == 1){
            db1UserServiceItemMapper.insertSelectiveList(userServiceItemList);
        }

        return 0;
    }
}
